﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Dapper.IService;
using Dapper.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

//using System.Web;
//using System.Web.Http;

namespace DapperCore.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        public IUserService _userService;
        public ITestService _testService;
        public UserController(IUserService userService, ITestService testService)
        {
            this._userService = userService;
            this._testService = testService;
        }

        [HttpGet]
        public List<User> GetUsers()
        {
            return _userService.GetUsers();
        }
        [HttpGet]
        public User GetTests(string Id)
        {
            return _testService.GetById(Id);
        }


        [HttpGet]
        public User GetUser(string userId)
        {
            return _userService.GetUser(userId);
        }


        [HttpGet]

        public bool AddUserCache(string userId)
        {
            User user = _userService.GetUser(userId);
            return Dapper.Redis.RedisHelper.Default.SetStringKey<User>("user_" + userId, user, TimeSpan.FromMinutes(1));
        }

        [HttpGet]

        public User GetUserCache(string userId)
        {
            return Dapper.Redis.RedisHelper.Default.GetStringKey<User>("user_" + userId);
        }
    }
}